home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / prog_ed.c < prev    next >
C/C++ Source or Header  |  1995-02-19  |  25KB  |  773 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; prog_ed.c : program editor
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <osbind.h>        /* needed for Vsync() */
  22. #include <string.h>
  23. #include <gemfast.h>
  24. #include <aesbind.h>
  25. #include <vdibind.h>
  26. #include "gm/gem_man.h"
  27. #include "eked-m1.h"
  28. #include "defs.h"
  29. #include "types.h"
  30. #include "externs.h"
  31.  
  32. #define T_WID        50
  33. #define WIDTH2TIME(w)    (((w) == 0) ? 0 : 2 * (w) - 1)
  34. #define TIME2WIDTH(t)    (((t) + 1) / 2)
  35. #define HEIGHT2SNUM(h)    (((h) == 0) ? 0 : 2 * (h) + (((h) > 0) ? 1 : -1))
  36. #define SNUM2HEIGHT(n)    (((n) >= 0) ? (n) / 2 : -((-(n)) / 2))
  37. #define HEIGHT2UNUM(h)    (h)
  38. #define UNUM2HEIGHT(n)    (n)
  39. #define NO_GRAPH    (-2)    /* -1 used by objc_find()! */
  40.  
  41. /*
  42.  *    Graph control point data structure
  43.  */
  44. typedef struct {
  45.   int c_x;        /* x offset from GEM graph object */
  46.   int c_y;        /* y offset from GEM graph object */
  47. #define FIXED        (-1)
  48. #define FOLLOW        (-2)
  49.   int x_ob;        /* GEM object for x parameter or FIXED or FOLLOW */
  50.   int y_ob;        /* GEM object for y parameter or FIXED or FOLLOW */
  51. } CTRL_POINT;
  52.  
  53. /*
  54.  *    Graph data structure
  55.  */
  56. typedef struct {
  57.   int x_axis_x1;    /* x axis */
  58.   int x_axis_x2;
  59.   int x_axis_y;
  60.   int y_axis_x;        /* y axis 1 (note on) */
  61.   int y_axis_y1;
  62.   int y_axis_y2;    /* y axis 2 (note off) */
  63.   int y_axis2_x;
  64.   int y_min;        /* minimum y value for control point */
  65.   int y_max;        /* maximum y value for control point */
  66.   int n_points;        /* number of control points */
  67.   CTRL_POINT point[7];    /* control point array */
  68.   int vsync_flag;    /* flag to force Vsync() call before redraw */
  69. } GRAPH;
  70.  
  71. static BITBLK *wave_image[4];
  72.  
  73. static OBJECT *pitch_mod;
  74. static OBJECT *pitch1;
  75. static OBJECT *pitch2;
  76. static OBJECT *filter_mod;
  77. static OBJECT *filter1;
  78. static OBJECT *filter2;
  79. static OBJECT *misc;
  80. static OBJECT *amp1;
  81. static OBJECT *amp2;
  82. static OBJECT *effect_route;
  83. static OBJECT *effect1;
  84. static OBJECT *effect2;
  85.  
  86. static BANK *edit_bank;            /* bank of program being edited */
  87. static int number;            /* number of program being edited */
  88. static int in_use;            /* editor in use flag */
  89. static int graph_handle;        /* vdi handle for drawing graphs */
  90. static int work_w;            /* width of window contents */
  91. static int work_h;            /* height of window contents */
  92. static BYTE data[PROGRAM_SIZE];        /* private copy of program */
  93. static BYTE compare[PROGRAM_SIZE];    /* another copy for compare op */
  94.  
  95. static void prog_setup();
  96. static void display(int x_pos, int y_pos, GRECT *clip, long usr_val);
  97. static int action(int handle, E_TYPE type, void *event,
  98.                   int x_pos, int y_pos, long usr_val);
  99. static void save_prog(BYTE *p);
  100. static void do_click(int handle, int m_x, int m_y);
  101. static void setup(int x_pos, int y_pos);
  102. static void gpara_setup(OBJECT *tree, int graph_ob,
  103.                         PARAMETER table[], int size);
  104. static void gpara_edit(int handle, OBJECT *tree, int graph_ob,
  105.                        PARAMETER table[], int size, int m_x, int m_y);
  106. static void graph_edit(int handle, OBJECT *tree, int ob,
  107.                        PARAMETER table[], int size, int m_x, int m_y);
  108. static void graph_drag(int handle, OBJECT *tree, int ob,
  109.                        int x_offset, int y_offset,
  110.                        CTRL_POINT coord[], int n_move, int link,
  111.                        VRECT *bound, GRECT *area);
  112. static int graph_draw(PARMBLK *p);
  113. static PARAMETER *find_parameter(PARAMETER table[], int size, int ob);
  114. static void para_setup(OBJECT *tree, PARAMETER table[], int size);
  115. static int misc_buttons(int handle, int ob);
  116.  
  117. void pe_init()
  118. {
  119.   static GRAPH pitch1_graph = {
  120.     4, 187, 56,        8, 4, 108, 128,        7, 105,         6,
  121.     {
  122.       {8,        66,    FIXED,        P1_ST_LEV},
  123.       {8+T_WID,    10,    P1_AT_TIME,    P1_AT_LEV},
  124.       {8+2*T_WID,    56,    P1_DC_TIME,    FIXED},
  125.       {128,    56,    FIXED,        FIXED},
  126.       {128+T_WID,    20,    P1_RL_TIME,    P1_RL_LEV},
  127.       {187,    20,    FIXED,        FOLLOW}
  128.     }
  129.   };
  130.   
  131.   static GRAPH pitch2_graph = {
  132.     4, 187, 56,        8, 4, 108, 128,        7, 105,         6,
  133.     {
  134.       {8,        105,    FIXED,        P2_ST_LEV},
  135.       {8+T_WID,    7,    P2_AT_TIME,    P2_AT_LEV},
  136.       {8+2*T_WID,    56,    P2_DC_TIME,    FIXED},
  137.       {128,    56,    FIXED,        FIXED},
  138.       {128+T_WID,    80,    P2_RL_TIME,    P2_RL_LEV},
  139.       {187,    80,    FIXED,        FOLLOW}
  140.     }
  141.   };
  142.   
  143.   static GRAPH filter1_graph = {
  144.     4, 235, 56,         8, 4, 108, 176,    7, 105,         7,
  145.     {
  146.       {8,        56,    FIXED,        FIXED},
  147.       {8+T_WID,    90,    F1_AT_TIME,    F1_AT_LEV},
  148.       {8+2*T_WID,    56,    F1_DC_TIME,    F1_DC_LEV},
  149.       {8+3*T_WID,    45,    F1_SS_TIME,    F1_SS_LEV},
  150.       {176,    45,    FIXED,        FOLLOW},
  151.       {176+T_WID,    40,    F1_RL_TIME,    F1_RL_LEV},
  152.       {235,    40,    FIXED,        FOLLOW}
  153.     }
  154.   };
  155.   
  156.   static GRAPH filter2_graph = {
  157.     4, 235, 56,         8, 4, 108, 176,    7, 105,         7,
  158.     {
  159.       {8,        56,    FIXED,        FIXED},
  160.       {8+T_WID,    7,      F2_AT_TIME,    F2_AT_LEV},
  161.       {8+2*T_WID,    105,    F2_DC_TIME,    F2_DC_LEV},
  162.       {8+3*T_WID,    20,    F2_SS_TIME,    F2_SS_LEV},
  163.       {176,    20,    FIXED,        FOLLOW},
  164.       {176+T_WID,    40,    F2_RL_TIME,    F2_RL_LEV},
  165.       {235,    40,    FIXED,        FOLLOW}
  166.     }
  167.   };
  168.   
  169.   static GRAPH amp1_graph = {
  170.     4, 235, 104,         8, 4, 108, 176,    5, 104,         6,
  171.     {
  172.       {8,        104,    FIXED,        FIXED},
  173.       {8+T_WID,    5,    A1_AT_TIME,    A1_AT_LEV},
  174.       {8+2*T_WID,    104,    A1_DC_TIME,    A1_DC_LEV},
  175.       {8+3*T_WID,    80,    A1_SS_TIME,    A1_SS_LEV},
  176.       {176,    80,    FIXED,        FOLLOW},
  177.       {176+T_WID,    104,     A1_RL_TIME,    FIXED}
  178.     }
  179.   };
  180.   
  181.   static GRAPH amp2_graph = {
  182.     4, 235, 104,         8, 4, 108, 176,    5, 104,         6,
  183.     {
  184.       {8,        104,    FIXED,        FIXED},
  185.       {8+T_WID,    5,    A2_AT_TIME,    A2_AT_LEV},
  186.       {8+2*T_WID,    104,    A2_DC_TIME,    A2_DC_LEV},
  187.       {8+3*T_WID,    80,    A2_SS_TIME,    A2_SS_LEV},
  188.       {176,    80,    FIXED,        FOLLOW},
  189.       {176+T_WID,    104,     A2_RL_TIME,    FIXED}
  190.     }
  191.   };
  192.  
  193.   static USERBLK pitch1_ub = {(void *) &graph_draw, (long) &pitch1_graph};
  194.   static USERBLK pitch2_ub = {(void *) &graph_draw, (long) &pitch2_graph};
  195.   static USERBLK filter1_ub = {(void *) &graph_draw, (long) &filter1_graph};
  196.   static USERBLK filter2_ub = {(void *) &graph_draw, (long) &filter2_graph};
  197.   static USERBLK amp1_ub = {(void *) &graph_draw, (long) &1_graph};
  198.   static USERBLK amp2_ub = {(void *) &graph_draw, (long) &2_graph};
  199.  
  200.   graph_handle = gm_opnvwk();
  201.   vsf_color(graph_handle, WHITE);
  202.   vsm_type(graph_handle, 4);
  203.   vsm_color(graph_handle, BLACK);
  204.   vsl_udsty(graph_handle, 0xAAAA);
  205.  
  206.   rm_gaddr(R_TREE, PITCH_MOD, &pitch_mod);
  207.   rm_gaddr(R_TREE, PITCH1, &pitch1);
  208.   rm_gaddr(R_TREE, PITCH2, &pitch2);
  209.   rm_gaddr(R_TREE, FILTER_MOD, &filter_mod);
  210.   rm_gaddr(R_TREE, FILTER1, &filter1);
  211.   rm_gaddr(R_TREE, FILTER2, &filter2);
  212.   rm_gaddr(R_TREE, MISC, &misc);
  213.   rm_gaddr(R_TREE, AMP1, &1);
  214.   rm_gaddr(R_TREE, AMP2, &2);
  215.   rm_gaddr(R_TREE, EFFECT_ROUTE, &effect_route);
  216.   rm_gaddr(R_TREE, EFFECT1, &effect1);
  217.   rm_gaddr(R_TREE, EFFECT2, &effect2);
  218.  
  219.   if(char_h >= 16){
  220.     wave_image[0] = (BITBLK *) filter_mod[FM_WAVE].ob_spec;
  221.     wave_image[1] = (BITBLK *) pitch_mod[PM_WAVE].ob_spec;
  222.     rm_gaddr(R_IMAGEDATA, DOWNSAW, wave_image + 2);
  223.     rm_gaddr(R_IMAGEDATA, SQUARE, wave_image + 3);
  224.   }
  225.   else{
  226.     rm_gaddr(R_IMAGEDATA, TRIANGLE_L, wave_image);
  227.     rm_gaddr(R_IMAGEDATA, UPSAW_L, wave_image + 1);
  228.     rm_gaddr(R_IMAGEDATA, DOWNSAW_L, wave_image + 2);
  229.     rm_gaddr(R_IMAGEDATA, SQUARE_L, wave_image + 3);
  230.   }
  231.  
  232.   pitch1[P1_GRAPH].ob_spec = (long) &pitch1_ub;
  233.   pitch2